﻿

//获取QueryString的数组
var getQueryString = function () {
    /// <summary>
    /// 获取QueryString的数组
    /// </summary>
    /// <returns>方法的返回值</returns>
    var result = location.search.match(new RegExp("[\?\&][^\?\&]+=[^\?\&]+", "g"));
    if (result == null) {
        return "";
    }
    for (var i = 0; i < result.length; i++) {
        result[i] = result[i].substring(1);
    }

    return result;
};

//根据QueryString参数名称获取值
var getQueryStringByName = function (name) {
    /// <summary>
    /// 根据QueryString参数名称获取值
    /// </summary>
    /// <param name="name">获取集合成员的名称</param>
    /// <returns>方法的返回值</returns>
    var result = location.search.match(new RegExp("[\?\&]" + name + "=([^\&]+)", "i"));
    if (result == null || result.length < 1) {
        return "";
    }
    return result[1];
};

//根据QueryString参数索引获取值
var getQueryStringByIndex = function (index) {
    /// <summary>
    /// 根据QueryString参数索引获取值
    /// </summary>
    /// <param name="index">获取集合成员的索引</param>
    /// <returns>方法的返回值</returns>
    if (index == null) {
        return "";
    }
    var queryStringList = getQueryString();
    if (index >= queryStringList.length) {
        return "";
    }
    var result = queryStringList[index];
    var startIndex = result.indexOf("=") + 1;
    result = result.substring(startIndex);
    return result;
};

var GetCurrentDate = function () {
    var dat = new Date(); //生成日期
    var year = dat.getFullYear(); //取得年
    var month = dat.getMonth() + 1; //取得月
    var date1 = dat.getDate(); //取得天
    var hour = dat.getHours(); //取得小时
    var minutes = dat.getMinutes(); //取得分钟
    var second = dat.getSeconds(); //取得秒

    return year + "年" + month + "月" + date1 + "日" + " " + hour + "时" + minutes + "分" + second + "秒";
};

var GetCurrentDateForViewLogList = function () {
    var dat = new Date(); //生成日期
    var year = dat.getFullYear(); //取得年
    var month = dat.getMonth() + 1; //取得月
    var date1 = dat.getDate(); //取得天
    var hour = dat.getHours(); //取得小时
    var minutes = dat.getMinutes(); //取得分钟
    var second = dat.getSeconds(); //取得秒
//    year = year.toString();
//    year = year.substring(2);
    return month + "-" + date1;
};

var CheckedPermession = function () {
    postJson({
        ajaxUrl: "FullTextSearchList.aspx",
        postData: { 'Action': 'CheckRight', 'ResourceID': id, 'r': Math.random() },
        callback: function (data) {
            if (data.Msg == "ok") {
                var url = "Client/Document/ShowDocument.aspx?ID=" + id + "&r=" + Math.random();
            }
            else {
                var url = "../../ErrorPage.aspx?ErrorType=&ErrorMsg=" + encodeURI(data.Msg) + "&r=" + Math.random();
            }
        }
    });
};

//Ajax异步请求
var ajax = function (options) {
    var p = options;
    if (p.type == undefined) p.type = 'POST';
    if (p.contentType == undefined) p.contentType = "text/json";
    if (p.async == undefined) p.async = true;
    $.ajax({
        type: p.type,
        cache: false,
        async: p.async,
        url: p.ajaxUrl,
        data: p.postData,
        dataType: "json",
        contentType: p.contentType,
        success: function (result) {
            p.success(result);
        },
        error: function (result, b) {
              
        }
    });
};

//异步获取服务器数据 采用jquery $.getJSON
var getJson = function (options) {
    var p = options;
    $.getJSON(p.ajaxUrl, p.postData, function (result) {
        p.callback(result);
    });
};

//获取服务器数据 采用jquery $.post
var postJson = function (options) {
    var p = options;
    $.post(p.ajaxUrl, p.postData, function (result) {
        p.callback(result);
    }, "json");
       
};

//把读出来的json格式时间传入这个方法内  
var renderTime = function (date) {
    /// <summary>
    /// 把读出来的json格式时间传入这个方法内
    /// </summary>
    if(date == null || date.indexOf("/Date(") == -1 ){ return date;}
    var da = new Date(parseInt(date.replace("/Date(", "").replace(")/", "").split("+")[0]));
    var res = da.getFullYear() + "-" + (da.getMonth() + 1) + "-" + da.getDate();// + " " + da.getHours() + ":" + da.getMinutes() + ":" + da.getSeconds();
    return res;
};

//把读出来的json格式时间传入这个方法内  
var renderTimeFotHMS = function (date) {
    /// <summary>
    /// 把读出来的json格式时间传入这个方法内
    /// </summary>
    var da = new Date(parseInt(date.replace("/Date(","").replace(")/","").split("+")[0]));  
    return da.getFullYear()+"-"+ (da.getMonth()+1)+"-" +da.getDate()+" " +da.getHours()+":"+da.getSeconds()+":"+da.getMinutes(); 

};

var toJSONDate = function (key) {
    return "\/Date(" + key + "+0800)\/";
};
    
//计算字符长度   参数—>最大值：内容
var sumCharCode = function(maxNum,content){
    var maxNum = maxNum;
    var content = content;
    var iLen = 0;
    for (i = 0; i < content.length; i++) iLen += content.charAt(i).charCodeAt() > 255 ? 1 : 0.5;
    maxNum - Math.floor(iLen) >= 0 ? sendFlag = 0 : sendFlag = 1;
    if (sendFlag == 1) return true;
};
